package tal.shorer.gameoflife;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainMenu extends Activity {
	public final static String EXTRA_MESSAGE_SIZE= "tal.shorer.gameoflife.MESSAGE_SIZE";
	public final static String EXTRA_MESSAGE_RULE = "tal.shorer.gameoflife.MESSAGE_RULE";
	public final static String EXTRA_MESSAGE_INTERVAL = "tal.shorer.gameoflife.MESSAGE_INTERVAL";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_menu);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main_menu, menu);
		return true;
	}

	private void AddParamToIntent(Intent intent, String name, int editTextID) {
		EditText editText = (EditText)findViewById(editTextID);
		String message = editText.getText().toString();
		intent.putExtra(name, message);
	}
	
	/** Called when the user clicks the Start button */
	public void sendMessage(View view) {
	    // Do something in response to button
		Intent intent = new Intent(this, GameOfLifeActivity.class);
		AddParamToIntent(intent, EXTRA_MESSAGE_SIZE, R.id.edit_param_size);
		AddParamToIntent(intent, EXTRA_MESSAGE_RULE, R.id.edit_param_rule);
		AddParamToIntent(intent, EXTRA_MESSAGE_INTERVAL, R.id.edit_param_interval);
		startActivity(intent);
	}

}
